// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
// 自定义指令
import directive from './directives'
// 导入小图标插件
import 'font-awesome/css/font-awesome.css'
// 导入公共样式
import './assets/less/common.less'
// 导入element样式
import 'element-ui/lib/theme-chalk/index.css'
// 引入 ECharts 主模块
import Echarts from 'echarts'

// 导入仓库
import store from './store'

// 导入封装好的axios插件
import httpAxios from './http'
// 使用自己封装好的插件
Vue.use(httpAxios)
// 注册使用自定义指令
Vue.use(directive)
Vue.use(ElementUI)

Vue.prototype.$echarts = Echarts

Vue.config.productionTip = false

// 本地检测token是否已经过期(token过期直接送去登录页)
if (store.state.user.info.token_exp && Date.now() > store.state.user.info.token_exp * 1000) {
  // console.log("token已经过期")
  // 清空本地用户记录
  let redirectUrl = router.currentRoute.fullPath || '/'

  store.dispatch('user/clearUserInfo').then(() => {
    // 跳转
    router.push({
      path: '/',
      redirect: redirectUrl
    })
  })
}

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
